<template>
  <div>
    <swiper :options="swiperOptions">
       <swiper-slide v-for="(page,index) in pages" :key='index'>
          <div class="icons" v-for="item in page" :key='item.id'>
            <div class="icon">
                <div class="icon-wrap">
                  <img class="item-img" :src="item.imgUrl" alt="">
                </div>
                <p class="icon-desc">{{item.desc}}</p>
            </div>
          </div>
        </swiper-slide>
     </swiper>
  </div>
</template>

<script>
export default {
  props: {
    iconList: Array
  },
  name: 'homeIcons',
  data () {
    return {
      swiperOptions: {
        autoPlay: false
      }
    }
  },

  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        };
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .icons
    position: relative;
    overflow: hidden;
    height: 0;
    padding-bottom: 50%;
    float: left;
    width: 25%;
    height: 0;  //添加内容也不会撑开高度
    padding-bottom: 25%;
    text-align: center;
    .icon-wrap
      overflow:hidden;
      position: absolute;
      top: 0;
      left: 0;
      bottom: .44rem;
      right: 0;
      .item-img
        box-sizing: border-box;
        padding :.1rem;
        width: 100%;
        height: 100%;
    .icon-desc
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: .44rem;
      line-height: .44rem;
      color: $darkColor;
      ellipsis()
</style>
